﻿Public Class frmEditCategorys 
    Dim Strsql As String
    Dim _Mysql As New ClsSQLhelper
    Dim On_Load As Boolean = True
    Public Primary_Key As Integer
    Public Section_ID As Integer
#Region "Function"
    Sub Load_Data()
        Try
            Strsql = "Select * from category where category_id = " & Primary_Key
            Dim DT_Catetory As DataTable
            DT_Catetory = _Mysql.GetMYSQLDataTable(Strsql, "category")
            Me.Txtname.Text = DT_Catetory.Rows(0).Item("category_name").ToString
            Me.TxtNote.Text = DT_Catetory.Rows(0).Item("note").ToString
            Me.ChkActive.Checked = IIf(DT_Catetory.Rows(0).Item("active") = True, True, False)

        Catch ex As Exception
            With frmDebug
                .lblFormName.Text = Me.Name
                .lblFunctionName.Text = "Load_Data"
                .MemoErr_Description.Text = ex.Message
                .MemoSQL.Text = Strsql
                .ShowDialog()
            End With
        End Try
    End Sub
#End Region
    Private Sub frmEditCategorys_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Load_Data()
    End Sub

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.Dispose()
    End Sub

    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try
            If Me.Txtname.Text.Trim = "" Then Exit Sub
            If MsgBox("คุณต้องการบันทึกข้อมูลหรือไม่", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ยืนยันการบันทึก") = MsgBoxResult.No Then Exit Sub

            Dim DT As New DataTable
            Strsql = "Update category set category_name='" & Me.Txtname.Text & "',note= '" & Me.TxtNote.Text & "',sectionid= " & Section_ID & ",active = " & IIf(Me.ChkActive.Checked = True, 1, 0) & "  where category_id = " & Primary_Key
            _Mysql.MySQLExecute(Strsql)
            DialogResult = Windows.Forms.DialogResult.OK
            MsgBox("เพิ่มข้อมูลเข้าเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Me.Dispose()


        Catch ex As Exception

            With frmDebug
                .lblFormName.Text = Me.Name
                .lblFunctionName.Text = "BtnSave_Click"
                .MemoErr_Description.Text = ex.Message
                .MemoSQL.Text = Strsql
                .ShowDialog()
            End With
        End Try
    End Sub
End Class